package com.bosssoft.cloud.wechat.common.infra.config;

import com.bosssoft.cloud.wechat.infrastructure.constant.EipsConfigConsts;
import com.bosssoft.cloud.wechat.infrastructure.processor.BaseControllerHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;

/**
 * @author wcy create on 2021/6/24 16:54 下午
 */

@Slf4j
@Component
public class EipsControllerHandler implements BaseControllerHandler {
    @Override
    public String getPackageName() {
        return EipsConfigConsts.EINVOICE_CONTROLLER_PATH;
    }

    @Override
    public String getPrefix() {
        return EipsConfigConsts.EINVOICE_CONTROLLER_PREFIX;
    }

    @Override
    public boolean isPattern(Class<?> clazz) {
        if (null != clazz) {
            return clazz.getPackage().getName().startsWith(getPackageName());
        }
        return false;
    }

    @Override
    public RequestMappingInfo combineRequestMappingInfo(RequestMappingInfo original) {
        RequestMappingInfo requestMappingInfo = RequestMappingInfo.paths(getPrefix()).build().combine(original);
        if (log.isInfoEnabled()) {
            log.info("will change {} onto {};", original, requestMappingInfo);
        }
        return requestMappingInfo;
    }
}
